package it.unibo.mumu;

import it.unibo.mumu.R;
import it.unibo.mumu.entity.Planet;
import it.unibo.mumu.entity.UniverseSelected;
import it.unibo.mumu.util.SingletonSupport;
import android.support.v4.app.Fragment;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

/**
 * A fragment representing a single step in a wizard. The fragment shows a dummy title indicating
 * the page number, along with some dummy text.
 *
 * <p>This class is used by the {@link CardFlipActivity} and {@link
 * ScreenSlideActivity} samples.</p>
 */
public class ScreenSlidePageFragment extends Fragment {
    /**
     * The argument key for the page number this fragment represents.
     */
    public static final String ARG_PAGE = "page";

    /**
     * The fragment's page number, which is set to the argument value for {@link #ARG_PAGE}.
     */
    private int mPageNumber;

    /**
     * Factory method for this fragment class. Constructs a new fragment for the given page number.
     */
    public static ScreenSlidePageFragment create(int pageNumber) {
        ScreenSlidePageFragment fragment = new ScreenSlidePageFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PAGE, pageNumber);
        fragment.setArguments(args);
        return fragment;
    }

    public ScreenSlidePageFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mPageNumber = getArguments().getInt(ARG_PAGE);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        // Inflate the layout containing a title and body text.
        ViewGroup rootView = (ViewGroup) inflater
                .inflate(R.layout.fragment_screen_slide_page, container, false);
        ImageView iv = (ImageView) rootView.findViewById(R.id.currentImage);
        UniverseSelected universe = SingletonSupport.getInstance().getUniverses().get(SingletonSupport.getInstance().getRealUniverseID());
        Planet planet = universe.getPlanets().get(SingletonSupport.getInstance().getRealPlanetID());

        
        
        //File imgFile = new  File(getActivity().getFilesDir().getPath()+ "/" + planet.getImageSetHappy().getSet().get(mPageNumber).getImagePath());
        //if(imgFile.exists()){
        //	Log.i("VIEWIMG", "almeno 1 file");
            
          //  iv.setImageBitmap(BitmapFactory.decodeFile(imgFile.getAbsolutePath()));
        
        if(SingletonSupport.getInstance().isHappiness()){
        	// immagini felici
        	iv.setImageBitmap(BitmapFactory.decodeFile(getActivity().getFilesDir().getPath()+ "/" + planet.getImageSetHappy().getSet().get(mPageNumber).getImagePath()));
        }else{
        	// immagini tristi
        	iv.setImageBitmap(BitmapFactory.decodeFile(getActivity().getFilesDir().getPath()+ "/" + planet.getImageSetSad().getSet().get(mPageNumber).getImagePath()));
        }
        
        
//        }else{
//        	Log.i("VIEWIMG", "no file");
//        }
        
 
       
        
         // cambiare qui la risorsa

        return rootView;
    }

    /**
     * Returns the page number represented by this fragment object.
     */
    public int getPageNumber() {
        return mPageNumber;
    }
}
